﻿package com.dg.gaming.api.common{

	import com.dg.gaming.api.common.msg.ITransmittable;
	import nanoxml.XMLElement;
	public class GameModel extends Observable implements IGameModel,ITransmittable {
		/**
		 * Type based game type i.e. each player takes their turn in a game e.g.
		 * board/card games.
		 */
		public static const GAME_TYPE_TURN_BASED:int=1;

		/**
		 * Real time game type i.e. everyone is playing at the same time e.g.
		 * arcade style game
		 */
		public static const GAME_TYPE_REAL_TIME:int=2;

		/** Game type from IGameModel e.g. GAME_TYPE_TURN_BASED or GAME_TYPE_REAL_TIME. */
		protected var gameType:int;

		/**
		 * <p>Set the state of the model (set values of the model equal to the
		 * values of this model by copying its values.  The inString is created
		 * from the flatten () method of GameModel.  The implementation of this
		 * method in the subclass should call the refreshObservers() method so that
		 * the screen gets updated correctly.</p>
		 *
		 * @param message   XMLElement created from flatten () method of this object.
		 * @throws TransmissionException
		 */
		public function setState(message:XMLElement):void {
		}

		/**
		 * <p>Returns the state/snapshot of a particular game.</p>
		 *
		 * @see com.dg.gaming.api.common.msg.ITransmittable#flatten()
		 */
		public function flatten():XMLElement {
			return null;
		}


		/**
		 * Blank constructor which can be called by a sub class.
		 */
		public function GameModel(gameType:int=-1) {
			super();// to Observable class

			this.gameType=gameType;
		}


		/**
		 * Refresh observers - calls the setChanged() and notifyObservers ()
		 * methods in the Observable class.
		 */
		public function refreshObservers():void {
			setChanged();
			notifyObservers();// notify any class which observe this class
		}
	}


}